local joy__wuniang = fk.CreateSkill {

  name = "joy__wuniang",

  tags = {  },

}



joy__wuniang:addEffect(fk.CardUsing, {
  name = "joy__wuniang",
  anim_type = "control",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joy__wuniang.name) and data.card.trueName == "slash" and
      not table.every(player.room:getOtherPlayers(player), function(p) return p:isNude() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#joy__wuniang1-choose"
    if player:usedSkillTimes("joy__xushen", Player.HistoryGame) > 0 and
      table.find(room.alive_players, function(p) return string.find(p.general, "guansuo") end) then
      prompt = "#joy__wuniang2-choose"
    end
    local to = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player), function(p)
      return not p:isNude() end), Util.IdMapper), 1, 1, prompt, joy__wuniang.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, player, target, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    local id = room:askForCardChosen(player, to, "he", joy__wuniang.name)
    room:obtainCard(player, id, false, fk.ReasonPrey)
    if not to.dead then
      to:drawCards(1, joy__wuniang.name)
    end
    if player:usedSkillTimes("joy__xushen", Player.HistoryGame) > 0 then
      for _, p in ipairs(room.alive_players) do
        if string.find(p.general, "guansuo") and not p.dead then
          p:drawCards(1, joy__wuniang.name)
        end
      end
    end
  end,
})
joy__wuniang:addEffect(fk.CardResponding, {
  name = "joy__wuniang",
  anim_type = "control",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joy__wuniang.name) and data.card.trueName == "slash" and
      not table.every(player.room:getOtherPlayers(player), function(p) return p:isNude() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#joy__wuniang1-choose"
    if player:usedSkillTimes("joy__xushen", Player.HistoryGame) > 0 and
      table.find(room.alive_players, function(p) return string.find(p.general, "guansuo") end) then
      prompt = "#joy__wuniang2-choose"
    end
    local to = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player), function(p)
      return not p:isNude() end), Util.IdMapper), 1, 1, prompt, joy__wuniang.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, player, target, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    local id = room:askForCardChosen(player, to, "he", joy__wuniang.name)
    room:obtainCard(player, id, false, fk.ReasonPrey)
    if not to.dead then
      to:drawCards(1, joy__wuniang.name)
    end
    if player:usedSkillTimes("joy__xushen", Player.HistoryGame) > 0 then
      for _, p in ipairs(room.alive_players) do
        if string.find(p.general, "guansuo") and not p.dead then
          p:drawCards(1, joy__wuniang.name)
        end
      end
    end
  end,
})

return joy__wuniang